/*
 * @Author: Wang Junwen wangjunwendut@163.com
 * @Date: 2024-10-28 09:47:22
 * @LastEditors: Wang Junwen wangjunwendut@163.com
 * @LastEditTime: 2024-10-28 09:47:40
 * @FilePath: \SGFEM\TestData\model\CORD1C_ApplyForce.hpp
 * @Description: 
 * 
 * Copyright (c) 2024 by 神工仿真, All Rights Reserved. 
 */
#pragma once
#include "DataStructure/Input/Node/NodeData.h"
#include "DataStructure/Input/Solver/DOFDirections.h"
#include "DataStructure/Input/Solver/Subcase.h"
#include "DataStructure/Input/Coordinate/CORD1CData.h"
#include "DataStructure/Input/Coordinate/CORD1RData.h"
#include "DataStructure/Input/Coordinate/CORD1SData.h"

#include "DBManager/Database/DatabaseFactory.h"
#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Subcase/ISubcaseService.h"
#include "DBManager/IService/Input/Node/INodeService.h"
#include "DBManager/IService/Input/Constraint/ISPCService.h"
#include "DBManager/IService/Input/Coordinate/ICORD1CService.h"
#include "DBManager/IService/Input/Coordinate/ICORD1RService.h"
#include "DBManager/IService/Input/Coordinate/ICORD1SService.h"


using SG::DataStructure::FEM::DOFDirections;
using SG::DataStructure::FEM::DofSet2Int;
using namespace SG::DBManager;
extern std::shared_ptr<DBServiceFactory> DB_SERVICEFACTORY;

/// 提供 局部坐标系定义
class CORD_Model
{
  public:
    CORD_Model ()
    {
        DB_SERVICEFACTORY->ClearDatabase ();
        Input (DB_SERVICEFACTORY);
    }

    /// @brief 写入模型数据
    void               Input (const DBServiceFactorySP dbServiceFactory);
    DBServiceFactorySP GetModel ()
    {
        return DB_SERVICEFACTORY;
    }

};

void CORD_Model::Input (const DBServiceFactorySP dbServiceFactory)
{
    // 节点写入
    {
        const auto nodeRepository = dbServiceFactory->get<INodeService> ();
        SG::DataStructure::FEM::NodeData node;
        node.m_id = 1;
        node.m_x[0] = 2.0;
        node.m_x[1] = 5.0;
        node.m_x[2] = 10.0;
        nodeRepository->Add (node);
        node.m_id = 2;
        node.m_x[0] = 10.4;
        node.m_x[1] = 13.7;
        node.m_x[2] = 19.0;
        nodeRepository->Add (node);
        node.m_id   = 3;
        node.m_x[0] = 18.8;
        node.m_x[1] = 22.4;
        node.m_x[2] = 28;
        nodeRepository->Add (node);
        node.m_id   = 4;
        node.m_x[0] = 27.2;
        node.m_x[1] = 31.1;
        node.m_x[2] = 37.0;
        nodeRepository->Add (node);
        node.m_id   = 5;
        node.m_x[0] = 35.6;
        node.m_x[1] = 39.8;
        node.m_x[2] = 46;
        nodeRepository->Add (node);
        node.m_id   = 6;
        node.m_x[0] = 44.0;
        node.m_x[1] = 48.5;
        node.m_x[2] = 55;
        nodeRepository->Add (node);
        node.m_id   = 7;
        node.m_x[0] = 52.4;
        node.m_x[1] = 57.2;
        node.m_x[2] = 64.0;
        nodeRepository->Add (node);        
        node.m_id   = 8;
        node.m_x[0] = 60.8;
        node.m_x[1] = 65.9;
        node.m_x[2] = 73.0;
        nodeRepository->Add (node);        
        node.m_id   = 9;
        node.m_x[0] = 69.2;
        node.m_x[1] = 74.6;
        node.m_x[2] = 82.0;
        nodeRepository->Add (node);        
        node.m_id   = 10;
        node.m_x[0] = 77.6;
        node.m_x[1] = 83.3;
        node.m_x[2] = 91.0;
        nodeRepository->Add (node);        
        node.m_id   = 11;
        node.m_x[0] = 86.0;
        node.m_x[1] = 92.0;
        node.m_x[2] = 100;
        nodeRepository->Add (node);        
        node.m_id   = 12;
        node.m_x[0] = 7.0;
        node.m_x[1] = 20.0;
        node.m_x[2] = 60.0;
        nodeRepository->Add (node);
    }

    // 柱坐标系
    {
        SG::DataStructure::FEM::CORD1CData cord1C;
        cord1C.m_id = 100;
        cord1C.m_g1 = 7;
        cord1C.m_g2 = 12;
        cord1C.m_g3 = 3;
        dbServiceFactory->get<ICORD1CService> ()->Add (cord1C);
    }

    // 直角坐标系
    {
        SG::DataStructure::FEM::CORD1RData cord1R;
        cord1R.m_id = 200;
        cord1R.m_g1 = 3;
        cord1R.m_g2 = 12;
        cord1R.m_g3 = 9;
        dbServiceFactory->get<ICORD1RService> ()->Add (cord1R);
    }

    // 球坐标系
    {
        SG::DataStructure::FEM::CORD1SData tempCORD1S;
        tempCORD1S.m_id = 300;
        tempCORD1S.m_g1 = 11;
        tempCORD1S.m_g2 = 12;
        tempCORD1S.m_g3 = 2;
        dbServiceFactory->get<ICORD1SService> ()->Add (tempCORD1S);
    }

    // 节点固定约束 SPC1
    {
        SG::DataStructure::FEM::SPCData spc;
        spc.m_sId = 1;
        spc.m_g   = 1;
        spc.m_c   = DofSet2Int ({ DOFDirections::DOF_Ux, DOFDirections::DOF_Uy, DOFDirections::DOF_Uz, DOFDirections::DOF_Rotx, DOFDirections::DOF_Roty, DOFDirections::DOF_Rotz });
        dbServiceFactory->get<ISPCService> ()->Add (spc);
    }

    // 工况
    {
        // subcase.
        SG::DataStructure::FEM::Subcase subcase;
        // subcase.m_id   = 1;
        // subcase.m_spc  = 1;
        // subcase.m_load = 1;
        // dbServiceFactory->get<ISubcaseService> ()->Add (subcase);
        subcase.AddParameter({"SUBCASE","1"});
        subcase.AddParameter({"SOL","101"});
        subcase.AddParameter({"SPC","1"});
        subcase.AddParameter({"LOAD","1"});
        dbServiceFactory->get<ISubcaseService> ()->Initial (subcase.Dump());
    }
}